package com.wise.service.portal.content.pagedecorate;

import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSONObject;
import com.wise.entities.content.Decorate;
import com.wise.framework.dao.SqlSelect;
import com.wise.framework.daomodel.DaoList;
import com.wise.framework.daomodel.DaoOne;
import com.wise.summer.v1.portal.content.pagedecorate.GetPageDecorateById;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

import java.util.List;


@Service
@SummerService
@Slf4j
public class GetPageDecorateByIdService implements SummerServiceBean<GetPageDecorateById> {

    @Override
    public void sum(GetPageDecorateById model) {

        SqlSelect select = SqlSelect.selec("*")
                .fromClassName(Decorate.class)
                .eqLang(Decorate._lang)
                .eq(Decorate.ALIAS, model.getId());
        List<Decorate> decorates = DaoList.s(Decorate.class, select);
        Decorate decorate;
        if (decorates.isEmpty()) {
            decorate = DaoOne.s(Decorate.class, model.getId(), null);
            // decorate.setContent(null);
            model.setSummerResult(decorate);
        } else {
            decorate = decorates.get(0);
            // decorate.setContent(null);
            model.setSummerResult(decorate);
        }
        log.info("model.getId():{}   {}", model.getId(), JSONObject.toJSONString(decorate));
    }
}
